package com.cloud.admin.service.impl;

import com.cloud.admin.model.entity.MFilm;
import com.cloud.admin.mapper.MFilmMapper;
import com.cloud.admin.service.MFilmService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 影视
 *
 * @author douhaichao code generator
 * @date 2022-09-29 21:08:24
 */
@Service
@AllArgsConstructor
public class MFilmServiceImpl extends ServiceImpl<MFilmMapper, MFilm> implements MFilmService {

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */
    @Override
    public MFilm selectOne(MFilm req) {
        QueryWrapper queryWrapper = new QueryWrapper<MFilm>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<MFilm> selectAll(MFilm req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<MFilm> selectPage(Page page, MFilm req) {
        IPage<MFilm> list = baseMapper.selectPage(
                page,
                new QueryWrapper<MFilm>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<MFilm> selectPageByLike(Page page, MFilm req) {
        QueryWrapper queryWrapper = new QueryWrapper();

        if (null != req.getId()) {
            queryWrapper.eq("id", req.getId());
        }

        if (!StrUtil.isEmpty(req.getName())) {
            queryWrapper.like("name", req.getName());
        }

        if (!StrUtil.isEmpty(req.getOtherName())) {
            queryWrapper.like("other_name", req.getOtherName());
        }

        if (!StrUtil.isEmpty(req.getImg())) {
            queryWrapper.like("img", req.getImg());
        }

        if (!StrUtil.isEmpty(req.getContent())) {
            queryWrapper.like("content", req.getContent());
        }

        if (!StrUtil.isEmpty(req.getUpdateInfomation())) {
            queryWrapper.like("update_infomation", req.getUpdateInfomation());
        }

        if (!StrUtil.isEmpty(req.getDirector())) {
            queryWrapper.like("director", req.getDirector());
        }

        if (!StrUtil.isEmpty(req.getPerformer())) {
            queryWrapper.like("performer", req.getPerformer());
        }

        if (null != req.getCountryId()) {
            queryWrapper.eq("country_id", req.getCountryId());
        }

        if (!StrUtil.isEmpty(req.getCountryName())) {
            queryWrapper.like("country_name", req.getCountryName());
        }

        if (null != req.getOneTypeId()) {
            queryWrapper.eq("one_type_id", req.getOneTypeId());
        }

        if (!StrUtil.isEmpty(req.getOneTypeName())) {
            queryWrapper.like("one_type_name", req.getOneTypeName());
        }

        if (null != req.getTwoTypeId()) {
            queryWrapper.eq("two_type_id", req.getTwoTypeId());
        }

        if (!StrUtil.isEmpty(req.getTwoTypeName())) {
            queryWrapper.like("two_type_name", req.getTwoTypeName());
        }

        if (null != req.getLanguageId()) {
            queryWrapper.eq("language_id", req.getLanguageId());
        }

        if (!StrUtil.isEmpty(req.getLanguageName())) {
            queryWrapper.like("language_name", req.getLanguageName());
        }

        if (null != req.getReleaseTime()) {
            queryWrapper.eq("release_time", req.getReleaseTime());
        }

        if (null != req.getLongTime()) {
            queryWrapper.eq("long_time", req.getLongTime());
        }

        if (null != req.getPlayCount()) {
            queryWrapper.eq("play_count", req.getPlayCount());
        }

        if (null != req.getTodayPlayCount()) {
            queryWrapper.eq("today_play_count", req.getTodayPlayCount());
        }

        if (null != req.getDetailCount()) {
            queryWrapper.eq("detail_count", req.getDetailCount());
        }

        if (null != req.getScore()) {
            queryWrapper.eq("score", req.getScore());
        }

        if (null != req.getCreateTime()) {
            queryWrapper.eq("create_time", req.getCreateTime());
        }

        if (null != req.getUpdateTime()) {
            queryWrapper.eq("update_time", req.getUpdateTime());
        }

        if (null != req.getIsDel()) {
            queryWrapper.eq("is_del", req.getIsDel());
        }
        IPage<MFilm> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(MFilm req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
